from goods.models import SKU
from orders.models import OrderInfo, OrderGoods
from rest_framework import serializers

# 1，order序列化器
class OrderInfoSerializer(serializers.ModelSerializer):
    class Meta:
        model = OrderInfo
        fields = "__all__"


# 2,order detail序列化器
class SKUSerializer(serializers.ModelSerializer):
    class Meta:
        model=SKU
        fields=("name", "default_image_url")


class OrderGoodsSerializer (serializers.ModelSerializer):
    # 1.重写sku字段
    sku=SKUSerializer (read_only=True)

    class Meta:
        model=OrderGoods
        fields=('count', 'price', 'sku')


class OrderInfoDetailSerializer(serializers.ModelSerializer):

    # 1,重写orderGoods字段
    skus=OrderGoodsSerializer (read_only=True, many=True)

    class Meta:
        model = OrderInfo
        fields = "__all__"



